import 'dart:convert';

void main() {
  //
  // print(int.parse("0x11"));
  //
  // String binaryStringWithPrefix = "01011010";
  // int? decimalValue = binaryStringWithPrefix.toInt0B();
  // print('Binary string "$binaryStringWithPrefix" as integer is: $decimalValue');
  // print('Binary string "$binaryStringWithPrefix" as integer is: ${decimalValue?.toByteArray().toHexStrSpace}');

  final map = {
    0x5099: [1, 2, 3, 4, 5],
    0x5091: [11, 3, 4, 41, 25],
    0x5092: [13, 24, 36, 74, 57],
  };
  // 将 int 类型的键转换为 "0x..." 格式的字符串
  final convertedMap = map.map<String, List<int>>(
    (key, value) => MapEntry('$key', value),
  );
  final json = jsonEncode(convertedMap);
  print(json);
  // 解码 JSON 并还原原始 Map
  final decoded = jsonDecode(json) as Map<String, dynamic>;
  final restoredMap = decoded.map<int, List<int>>(
    (key, value) => MapEntry(
      int.parse(key), // 将 "0x5099" 转回 int
      (value as List<dynamic>).cast<int>(), // 将 dynamic List 转 List<int>
    ),
  );
  print(restoredMap);
}
